﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Login : MonoBehaviour, CmdLineProcess {
    public CmdLineControl CmdControl;
    private string UserName;

    // Use this for initialization
    void Start () {
        CmdControl.RegisterProcess("Login", this);
        CmdControl.SetCurrentProcess("Login");

        // 初始化相关信息
        UserName = "";
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    public void EnterIntoProcess(string Param)
    {
        CmdControl.SetInfo("Login:");
        CmdControl.SetInputType(InputType.Normal);
    }

    public void InputCmdLine(string CmdLine)
    {
        // 如果输入为空，则让其重新输入
        if(CmdLine.Length == 0)
        {
            if(UserName.Length == 0)
            {
                CmdControl.SetInfo("Login:");
                CmdControl.SetInputType(InputType.Normal);
            }
            else
            {
                CmdControl.SetInfo("Password:");
                CmdControl.SetInputType(InputType.Password);
            }
        }
        // 如果用户名还没输入，则重新输入用户名
        else if(UserName.Length == 0)
        {
            UserName = CmdLine;
            // 提示输入密码
            CmdControl.SetInfo("Password:");
            CmdControl.SetInputType(InputType.Password);
        }
        else
        {
            // 否则就是输入密码了
            CmdControl.SetInfo("验证中");
            CmdControl.SetInputType(InputType.Disable);
        }
    }

    public void LeaveFromProcess(string Param)
    {
        CmdControl.SetInfo("Bye Bye !!!\r\n");
    }
}
